home *** CD-ROM | disk | FTP | other *** search
- // Profile.lib - Cmm routines to interface with Windows' Profile
- // ver.1 (i.e. *.INI) files.
- //
- //
- //
- //**** GetProfileString(): return key value from .ini file
- // SYNTAX: string GetProfileString(string AppName,string KeyName,
- // string Default[,string FileName])
- // WHERE: AppName: Application name ([AppName] in .ini files)
- // KeyName: Key name under [AppName] in the .ini file
- // Default: Value returned if Key not found; if NULL then returns ""
- // FileName: name of profile file, defaults to WIN.INI if not supplied
- // RETURN: Return the profile string if found, else return Default if not found
- //
- //
- //**** WriteProfileString(): write key value to .ini file
- // SYNTAX: bool WriteProfileString(string AppName,string KeyName,
- // string Value[,string FileName])
- // WHERE: AppName: Application name ([AppName] in .ini files)
- // KeyName: Key name under [AppName] in the .ini file
- // Value: String to set KeyName equal to in the .INI file
- // FileName: name of profile file, defaults to WIN.INI if not supplied
- // RETURN: Return FALSE if failure, else success
- //
- //
- //**** GetProfileInt(): return key value from .ini file as an integer
- // SYNTAX: int GetProfileInt(string AppName,string KeyName,
- // int Default[,string FileName])
- // WHERE: AppName: Application name ([AppName] in .ini files)
- // KeyName: Key name under [AppName] in the .ini file
- // Default: Value returned if Key not found
- // FileName: name of profile file, defaults to WIN.INI if not supplied
- // RETURN: Return the profile integer if found, else return Default if not found
- //
- //
- //**** WriteProfileInt(): write key value to .ini file
- // SYNTAX: bool WriteProfileInt(string AppName,string KeyName,
- // int Value[,string FileName])
- // WHERE: AppName: Application name ([AppName] in .ini files)
- // KeyName: Key name under [AppName] in the .ini file
- // Value: Integer value to set KeyName equal to in the .INI file
- // FileName: name of profile file, defaults to WIN.INI if not supplied
- // RETURN: Return FALSE if failure, else success
- //
- //
- //**** GetProfileKeyList(): Get array of all keys in a profile file
- // SYNTAX: string[] GetProfileKeyList(string AppName[,string FileName])
- // WHERE: AppName: Application name ([AppName] in .ini files)
- // FileName: name of profile file, defaults to WIN.INI if not supplied
- // RETURN: Returns array of all keys under AppName; NULL if none found
- //
- //
-
-
- GetProfileString(pAppName,pKeyName,pDefault,pFileName)
- {
- lRetString[0] = lRetString[500] = '\0';
- lDefault = pDefault ? pDefault : "" ;
- lRetLength = ( 3 < va_arg() )
- ? DynamicLink("KERNEL","GETPRIVATEPROFILESTRING",SWORD16,PASCAL,
- pAppName,pKeyName,lDefault,lRetString,499,pFileName)
- : DynamicLink("KERNEL","GETPROFILESTRING",SWORD16,PASCAL,
- pAppName,pKeyName,lDefault,lRetString,499) ;
- lRetString[lRetLength] = 0;
- return lRetString;
- }
-
- WriteProfileString(pAppName,pKeyName,pValue,pFileName)
- {
- return ( 3 < va_arg() )
- ? DynamicLink("KERNEL","WRITEPRIVATEPROFILESTRING",SWORD16,PASCAL,
- pAppName,pKeyName,pValue,pFileName)
- : DynamicLink("KERNEL","WRITEROFILESTRING",SWORD16,PASCAL,
- pAppName,pKeyName,pValue) ;
- }
-
- GetProfileInt(pAppName,pKeyName,pDefault,pFileName)
- {
- return ( 3 < va_arg() )
- ? DynamicLink("KERNEL","GETPRIVATEPROFILEINT",UWORD16,PASCAL,
- pAppName,pKeyName,pDefault,pFileName)
- : DynamicLink("KERNEL","GETPROFILEINT",UWORD16,PASCAL,
- pAppName,pKeyName,pDefault) ;
- }
-
- WriteProfileInt(pAppName,pKeyName,pValue,pFileName)
- {
- sprintf(lValue,"%u",pValue);
- return ( 3 < va_arg() )
- ? WriteProfileString(pAppName,pKeyName,lValue,pFileName)
- : WriteProfileString(pAppName,pKeyName,lValue) ;
- }
-
- GetProfileKeyList(pAppName,pFileName)
- {
- // get buffer big enough to receive all strings
- lReceiveLen = 0;
- do {
- lReceiveLen += 500;
- lRetString[0] = lRetString[lReceiveLen+1] = '\0';
- lRetLength = ( 1 < va_arg() )
- ? DynamicLink("KERNEL","GETPRIVATEPROFILESTRING",SWORD16,PASCAL,
- pAppName,0,0,"",lRetString,lReceiveLen,pFileName)
- : DynamicLink("KERNEL","GETPROFILESTRING",SWORD16,PASCAL,
- pAppName,0,0,"",lRetString,lReceiveLen) ;
- } while ( lReceiveLen < (lRetLength + 10) );
-
- lKeyCount = 0;
- while ( 0 < lRetLength ) {
- if ( 1 < (lUsedLength = 1 + strlen(lRetString)) )
- strcpy(lKeyList[lKeyCount++],lRetString);
- lRetString += lUsedLength;
- lRetLength -= lUsedLength;
- }
-
- return ( lKeyCount ) ? lKeylist : NULL ;
- }
-